﻿using AutoMapper;
using IOA.MES.DataAccess.Entity;
using IOA.MES.DataAccess.VModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IOA.MES.Business
{
    /// <summary>
    /// 客户管理
    /// </summary>
    public class CustomerMgr
    {
        private MESContext mesDb = new MESContext("MES");

        /// <summary>
        /// 查询客户列表
        /// </summary>
        /// <returns></returns>
        public List<VCustomer> QueryCustomers()
        {
            var entities = mesDb.Customers.AsNoTracking().Where(_ => _.Valid).ToList();
            return Mapper.Map<List<VCustomer>>(entities.GroupBy(_ => new { _.CustomerCode, _.CustomerName }).Select(_ => _.FirstOrDefault()).ToList());
        }
    }
}
